<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><% model(2); %></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="php.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript" src="general.js"></script>
<script type="text/javascript">
    var wan_proto="<% nvram_get("wan_proto"); %>";
    var wan_ifname="<% nvram_get("wan_ifname"); %>";
    var man_ifname="";
    var ipv6_proto="<% nvram_get("ipv6_proto"); %>";
    var ipv6_ifname="";
    var wlan_ifname="<% nvram_get("wl0_ifname"); %>";
    var lan_ifname="<% nvram_get("lan_ifname"); %>";
    
    var default_interval = 2;

    function interval_change(value) {
    	$('#cpu_graph').attr('src', sprintf('graph_cpu.svg?%d', value));
		if (wan_ifname != "")
			$('#wan_graph').attr('src', sprintf('graph_if.svg?%s&%d', wan_ifname, value));
		if (man_ifname != "")
			$('#man_graph').attr('src', sprintf('graph_if.svg?%s&%d', man_ifname, value));
		if (ipv6_ifname != "")
			$('#ipv6_graph').attr('src', sprintf('graph_if.svg?%s&%d', ipv6_ifname, value));
		if (wlan_ifname != "")
			$('#wlan_graph').attr('src', sprintf('graph_if.svg?%s&%d', wlan_ifname, value));
		if (lan_ifname != "")
			$('#lan_graph').attr('src', sprintf('graph_if.svg?%s&%d', lan_ifname, value));
    }

    function process_element(elementId, value) {
		if (value != "")
			$(sprintf('#%s_ifname', elementId)).html(value);
		else
			$(sprintf('#%s_data', elementId)).remove();
    }

    function generate_page() {
		load_body();
	
		switch (wan_proto) {
			case 'l2tp':
			case 'pptp':
			case 'pppoe':
				man_ifname = wan_ifname;
		    	wan_ifname = "<% nvram_get("wan0_pppoe_ifname"); %>";
		    	break;
		    case 'wimax':
		    	wan_ifname = "<% nvram_get("wan0_wimax_ifname"); %>";
		    	break;
		    case 'usbmodem':
		    	wan_ifname = "<% nvram_get("wan0_pppoe_ifname"); %>";
		    	break;
		    case 'usbnet':
		    	wan_ifname = "<% nvram_get("wan0_ifname"); %>";
		    	break;
		}
	
		if (ipv6_proto == "tun6in4" || ipv6_proto == "tun6to4")
		    ipv6_ifname = "six0";
	
		process_element("wan", wan_ifname);
		process_element("man", man_ifname);
		process_element("ipv6", ipv6_ifname);
		process_element("wlan", wlan_ifname);
		process_element("lan", lan_ifname);
	
		interval_change(default_interval);
		elemByName('refresh').xval(default_interval);
    }

    $(document).ready(function() {
		generate_page();
	});
</script>
</head>
<body>
<form method="get" name="form" id="form" action="apply.cgi">
<input type="hidden" name="current_page" value="utilization.asp" />
<input type="hidden" name="next_page" value="utilization.asp" />
<input type="hidden" name="next_host" value="" />
<input type="hidden" name="group_id" value="" />
<input type="hidden" name="modified" value="0" />
<input type="hidden" name="action_mode" value="" />
<input type="hidden" name="first_time" value="" />
<input type="hidden" name="action_script" value="" />

<table class="main">
<thead>
<tr>
<td>Status &amp; Log - System Utilization</td>
</tr>
</thead>

<tr><td>
<table class="sect">
<tr>
    <th>Refresh Rate:</th>
    <td>
	<select name="refresh" class="content_input_fd" onchange="interval_change(this.value);">
	<option class="content_input_fd" value="1">1 second</option>
	<option class="content_input_fd" value="2">2 seconds</option>
	<option class="content_input_fd" value="5">5 seconds</option>
	<option class="content_input_fd" value="10">10 seconds</option>
	<option class="content_input_fd" value="30">30 seconds</option>
	<option class="content_input_fd" value="60">1 minute</option>
	</select></td>
</tr>
</table>
</td></tr>

<tr><td>
<table class="sect">
<thead>
<tr>
    <td colspan="2">System Load Monitoring</td>
</tr>
</thead>
<tr>
    <th>CPU:</th>
    <td>
    <table align="right">
    <tr><td style="border:0">
	<iframe id="cpu_graph" type="image/svg+xml" class="graph" src=""></iframe>
    </td></tr></table></td>
</tr>
</table>
</td></tr>

<tr><td>
<table class="sect">
<thead>
<tr>
    <td colspan="2">Interface Bandwidth Monitoring</td>
</tr>
</thead>
<tr id="wan_data">
    <th>WAN (<span id="wan_ifname"></span>):</th>
    <td>
    <table align="right">
    <tr><td style="border:0">
	<iframe id="wan_graph" type="image/svg+xml" class="graph" src=""></iframe>
    </td></tr></table></td>
</tr>
<tr id="man_data">
    <th>MAN (<span id="man_ifname"></span>):</th>
    <td>
    <table align="right">
    <tr><td style="border:0">
	<iframe id="man_graph" type="image/svg+xml" class="graph" src=""></iframe>
    </td></tr></table></td>
</tr>
<tr id="ipv6_data">
    <th>IPv6 (<span id="ipv6_ifname"></span>):</th>
    <td>
    <table align="right">
    <tr><td style="border:0">
	<iframe id="ipv6_graph" type="image/svg+xml" class="graph" src=""></iframe>
    </td></tr></table></td>
</tr>
<tr id="wlan_data">
    <th>Wi-Fi (<span id="wlan_ifname"></span>):</th>
    <td>
    <table align="right">
    <tr><td style="border:0">
	<iframe id="wlan_graph" type="image/svg+xml" class="graph" src=""></iframe>
    </td></tr></table></td>
</tr>
<tr id="lan_data">
    <th>LAN (<span id="lan_ifname"></span>):</th>
    <td>
    <table align="right">
    <tr><td style="border:0">
	<iframe id="lan_graph" type="image/svg+xml" class="graph" src=""></iframe>
    </td></tr></table></td>
</tr>
</table>
</td></tr>

</table>

<table class="foot">
<tr>  
    <td height="25" width="75%"></td>
    <td height="25">
	<input type="hidden" name="action_mode" value=" Refresh " />
	<div align="center"><font face="Arial"><input class="inputSubmit" onClick="document.form3.next_host.value = location.host; onSubmitCtrl(this, ' Refresh ')" type="submit" value="Refresh" name="action" /></font></div> 
	</td>
</tr>
</table>

</form>
</body>
</html>